//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//********************************************************* 

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;

namespace Microsoft.TridentWordAddIn.Setup.CustomActions
{
    public partial class InstallRetryDialog : Form
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="InstallRetryDialog"/> class.
        /// </summary>
        public InstallRetryDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Updates the process list.
        /// </summary>
        /// <param name="processes">The processes.</param>
        /// <param name="isInstallation">if set to <c>true</c> [is installation].</param>
        public void UpdateProcessList(List<Process> processes)
        {
            ListViewItem itemAdd;
            foreach (Process process in processes)
            {
                if (!string.IsNullOrEmpty(process.MainWindowTitle))
                {
                    if (process.ProcessName == "WINWORD")
                    {
                        itemAdd = this.lvResults.Items.Add(string.Format("Microsoft Office Word(Process Id: {0})", process.Id));
                    }
                    else
                    {
                        itemAdd = this.lvResults.Items.Add(process.MainWindowTitle);
                        itemAdd.Tag = process.Id;
                    }
                }
            }
        }

        /// <summary>
        /// Handles the Click event of the btnRetry control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnIgnore_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Ignore;
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the btnCancel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnRetry_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Retry;
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the btnClose control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}